package org.fxcontainer.actions
{
	import com.developmentarc.core.actions.actions.AbstractAction;
	
	import flash.events.Event;
	
	import mx.managers.BrowserManager;
	import mx.managers.IBrowserManager;
	
	import org.as3commons.logging.ILogger;
	import org.as3commons.logging.LoggerFactory;
	import org.fxcontainer.commands.URLChangeCommand;
	
	/**
	 * Navigate action handler.<br/> 
	 * Handles navigate action by changing browser URL.  
	 * @author Izzet_Mustafayev
	 */
	public class URLChangeAction extends AbstractAction
	{
		/**
		 * The logger. 
		 */
		static private var logger:ILogger = LoggerFactory.getClassLogger(URLChangeAction);
		
		/**
		 * Action constructor. Registers applyable command.
		 */
		public function URLChangeAction()
		{
			super();
			addCommand(URLChangeCommand.URL_CHANGE_CMD);
		}
		
		/**
		 * The broswer URL change command processing.
		 * @param command the command to process
		 */
		override public function applyAction(_command:Event):void 
		{
			if (null != _command && _command is URLChangeCommand){
				var command:URLChangeCommand = _command as URLChangeCommand;
				logger.debug("Change URL to: {0}", command.url);
				var browserManager:IBrowserManager = BrowserManager.getInstance();
				browserManager.setFragment(command.url);
			}
		}
	}
}